﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace WebApplication1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Test();
            CreateWebHostBuilder(args).Build().Run();
        }

        private static void Test()
        {
            var list = new List<Demo>
            {
                new Demo{ Id = 1, Name = "ABC", Qty = 1},
                new Demo{ Id = 2, Name = "ABD", Qty = 2},
                new Demo{ Id = 3, Name = "ABE", Qty = 3},
                new Demo{ Id = 4, Name = "ABC", Qty = 4},
                new Demo{ Id = 5, Name = "ABD", Qty = 5},
                new Demo{ Id = 6, Name = "ABF", Qty = 6},
                new Demo{ Id = 7, Name = "ABE", Qty = 7},
                new Demo{ Id = 8, Name = "ABC", Qty = 9},
            }.OrderByDescending(a => a.Id);
            Dictionary<string, Demo> res = new Dictionary<string, Demo>();
            foreach (var d in list)
            {
                if (res.ContainsKey(d.Name))
                {
                    continue;
                }
                res.Add(d.Name, d);
            }
            var result = res.Values.ToList();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }

    class Demo
    {
        public int Id { get; set; }

        public int Qty { get; set; }

        public string Name { get; set; }
    }
}
